package me.zhengjie.pm.projectstaff.domain;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import me.zhengjie.hr.employeebase.domain.EmployeeBase;
import me.zhengjie.pm.projectbase.domain.ProjectBase;

import javax.persistence.*;
import javax.validation.constraints.*;
import java.sql.Timestamp;
import java.io.Serializable;

/**
* @author ZGZ
* @date 2020-04-14
*/
@Entity
@Data
@Table(name="project_staff")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class ProjectStaff implements Serializable {

    /** ID */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Integer id;

    /** 项目 */
    @Column(name = "project_id")
    private Integer projectId;
    @OneToOne
    @JoinColumn(name = "project_id", insertable = false, updatable = false)
    private ProjectBase projectBase;

    /** 员工 */
    @Column(name = "staff_id")
    private Integer staffId;
    @OneToOne
    @JoinColumn(name = "staff_id", insertable = false, updatable = false)
    private EmployeeBase staffBase;

    /** 工作类型 */
    @Column(name = "work_type")
    private String workType;

    /** 工作职位 */
    @Column(name = "work_position")
    private String workPosition;

    /** 工作内容 */
    @Column(name = "work_content")
    private String workContent;

    /** 开始时间 */
    @Column(name = "start_time")
    private Timestamp startTime;

    /** 结束时间 */
    @Column(name = "end_time")
    private Timestamp endTime;

    public void copy(ProjectStaff source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}